<?php

class document {
	var $db;
 	var $smarty;	
	public function __construct($db, $smarty) {
		$this->db = $db;
		$this->smarty = $smarty;
	}
	
	public function RewriteLinkToFile($link) {
		$rightside = '';
		if($link =='home' || $link ==''){ 
			$pathname = "home";
			$file = 'home';
			$rightside = '1';
		}else if($link == 'about'){	
			$pathname = "about us";
			$file = 'about';
			$rightside = '1';
		}else if($link == 'photos'){	
			$pathname = "photos";	
			$file = 'photos';	
		}else if($link == 'event'){	
			$pathname = "event";			
			$file = 'event';	
		}else if($link == 'video'){	
			$pathname = "video";			
			$file = 'video';	
		}else if($link == 'news'){	
			$pathname = "news";			
			$file = 'news';		
		}else if($link == 'contact'){	
			$pathname = "contact us";			
			$file = 'contact';	
			$rightside = '1';
		}else if($link == 'request'){	
			$pathname = "request";			
			$file = 'request';
			$rightside = '1';
		}else if($link == 'map'){	
			$pathname = "map";			
			$file = 'map';	
			$rightside = '1';
		}else{
			$pathname = "page";			
			$file = 'page';		
			$rightside = '1';
		}
		if($rightside == '1')
			$this->Rightside();
		$path = "<a href='".FOLDER_HOST.$link."'>".ntp_text($pathname)."</a>";		
		$this->smarty->assign("PATHROOT", $path);		
		return $file;
	}
	
	public function RewriteLinkToName($link) {
		$url = str_replace('-'," ", $link);
		
		return $url;
	}
	
	public function RewriteNameToLink($link) {
		$link = JKDocument::khongdau($link);
		$url = str_replace(' ',"-", $link);
		return $url;
	}
	
	public function RewriteLink($id,$name) {
		$name = document::khongdau($name);
		$name = str_replace(' ',"-", $name);
		$url = $id.'_'.$name;
		return $url;
	}
	
	public function GetIdFromLink($link) {
		$url=explode("_",$link);
		return $url[0];
	}
	
	public function WritePath($path,$page,$cat,$product) {
		$str = '';
		if($page!=''){
			$str .= '<a href="'.$path.$page.'">';
		}	
	}
	
	public function ChangePath($str) {
		$str = str_replace("../".UPLOAD_FILES,FOLDER_HOST.UPLOAD_FILES, $str);
		return $str;
	}
	public function ChangeLink($str) {
		$str = str_replace('href="../','href="'.FOLDER_HOST, $str);
		$str = str_replace('data="../','data="'.FOLDER_HOST, $str);
		$str = str_replace('<param name="data" value="../','<param name="data" value="'.FOLDER_HOST, $str);
		$str = str_replace('<param name="src" value="../','<param name="src" value="'.FOLDER_HOST, $str);
		return $str;
	}
	
	public function ChangeLinkTags($str) {
		
		$arr= explode(",",$str);
		return $arr;
	}
	
	function khongdau($str) {
		$str = preg_replace("/(à|á|ạ|ả|ã|â|ầ|ấ|ậ|ẩ|ẫ|ă|ằ|ắ|ặ|ẳ|ẵ)/", 'a', $str);
		$str = preg_replace("/(è|é|ẹ|ẻ|ẽ|ê|ề|ế|ệ|ể|ễ)/", 'e', $str);
		$str = preg_replace("/(ì|í|ị|ỉ|ĩ)/", 'i', $str);
		$str = preg_replace("/(ò|ó|ọ|ỏ|õ|ô|ồ|ố|ộ|ổ|ỗ|ơ|ờ|ớ|ợ|ở|ỡ)/", 'o', $str);
		$str = preg_replace("/(ù|ú|ụ|ủ|ũ|ư|ừ|ứ|ự|ử|ữ)/", 'u', $str);
		$str = preg_replace("/(ỳ|ý|ỵ|ỷ|ỹ)/", 'y', $str);
		$str = preg_replace("/(đ)/", 'd', $str);
		$str = preg_replace("/(À|Á|Ạ|Ả|Ã|Â|Ầ|Ấ|Ậ|Ẩ|Ẫ|Ă|Ằ|Ắ|Ặ|Ẳ|Ẵ)/", 'A', $str);
		$str = preg_replace("/(È|É|Ẹ|Ẻ|Ẽ|Ê|Ề|Ế|Ệ|Ể|Ễ)/", 'E', $str);
		$str = preg_replace("/(Ì|Í|Ị|Ỉ|Ĩ)/", 'I', $str);
		$str = preg_replace("/(Ò|Ó|Ọ|Ỏ|Õ|Ô|Ồ|Ố|Ộ|Ổ|Ỗ|Ơ|Ờ|Ớ|Ợ|Ở|Ỡ)/", 'O', $str);
		$str = preg_replace("/(Ù|Ú|Ụ|Ủ|Ũ|Ư|Ừ|Ứ|Ự|Ử|Ữ)/", 'U', $str);
		$str = preg_replace("/(Ỳ|Ý|Ỵ|Ỷ|Ỹ)/", 'Y', $str);
		$str = preg_replace("/(Đ)/", 'D', $str);
		$str = preg_replace('/(")/', '', $str);
		$str = preg_replace("/(')/", '', $str);
		//$str = str_replace(" ", "-", str_replace("&*#39;","",$str));
		return $str;
	}	

	
	public function Rightside() {
		require_once 'galleryfrompicasa.class.php';
		$news = FIN_newsBean::getHomeNews($this->db,$_SESSION['LC_ALL']);
		foreach($news as $key => $item){
		$item->pro_link=document::RewriteLink($item->news_id,$item->news_title)."/";
		}
		$this->smarty->assign("NEWSDEMO", $news);		
		
		$gallery=new GalleryFromPicasa();
        $user_picasaweb=GUSER;

		/*$albums=$gallery->getAlbums($user_picasaweb,"61c");
		$albumfirst = array();
		$dem = 0;
		foreach ($albums as $key=>$value) {
			$dem++;
			if($dem == count($albums)){
			$albumfirst['src'] = $value['thumbnail'];
			$albumfirst['title'] = $value['title'];
			$albumfirst['id'] = $key;
			}
		}
		
		$this->smarty->assign("LISTALBUMDEMO",  $albumfirst);	*/
	}
	
	
}
?>
